home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Languages / MacGofer 0.22d / MacGofer Sources / machdep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-08  |  19.8 KB  |  243 lines  |  [TEXT/MPS ]

  1. /* --------------------------------------------------------------------------
  2.  * machdep.c:   Copyright (c) Mark P Jones 1991-1993.   All rights reserved.
  3.  *              See goferite.h for details and conditions of use etc...
  4.  *              Gofer version 2.28 January 1993
  5.  *
  6.  * Machine dependent code
  7.  * RISCOS specific code provided by Bryan Scatergood, JBS
  8.  * ------------------------------------------------------------------------*/
  9.  
  10. #if UNIX
  11. #include <signal.h>
  12. #include <sys/ioctl.h>
  13. #include <fcntl.h>
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16. #endif
  17.  
  18. #if (TURBOC | BCC)
  19. #include <dos.h>
  20. #include <conio.h>
  21. #include <io.h>
  22. #include <stdlib.h>
  23. #include <mem.h>
  24. #include <sys\stat.h>
  25. #include <time.h>
  26. extern unsigned _stklen = 8000;        /* Allocate an 8k stack segment       */
  27. #endif
  28.  
  29. #if ZTC
  30. #include <stdlib.h>
  31. #include <signal.h>
  32. #include <fcntl.h>
  33. #include <sys/types.h>
  34. #include <sys/stat.h>
  35. #endif
  36.  
  37. #if DJGPP
  38. #include <dos.h>
  39. #include <stdlib.h>
  40. #include <std.h>
  41. #include <signal.h>
  42. #include <fcntl.h>
  43. #include <sys/types.h>
  44. #include <sys/stat.h>
  45. #endif
  46.  
  47. #if RISCOS
  48. #include <assert.h>
  49. #include <signal.h>
  50. #include "swis.h"
  51. #include "os.h"
  52. #endif
  53.  
  54. #if MPW
  55. #include <stdio.h>
  56. #include <types.h>
  57. #include <memory.h>
  58.  
  59. /* Replaces stat.h for the Mac    */
  60. #include <Time.h>
  61. // typedef long time_t;
  62.  
  63. struct stat
  64. {
  65.   time_t st_mtime;
  66.   long   st_size;
  67. };
  68.  
  69. #pragma segment Machdep
  70. #endif
  71.  
  72. #if MAC
  73. #define    ILLEGAL_WINDOW    (-1)    /* In mac.h, but we can't include that here! */
  74.  
  75. #include <CursorCtl.h>        /* For rotating cursors/GC cursor */
  76. #endif
  77.  
  78.  
  79. /* --------------------------------------------------------------------------
  80.  * Machine dependent code is used in each of:
  81.  *    - The gofer interpreter        MACHDEP_GOFER
  82.  *    - The gofer compiler        MACHDEP_GOFC
  83.  *    - The compiler runtime system    MACHDEP_RUNTIME
  84.  * In many cases, the the same code is used in each part.  The following
  85.  * sections of code are enclosed in suitable #if ... #endif directives to
  86.  * indicate which sections require particular parts of the code.  Each of
  87.  * the three systems above defines one of the three symbols on the right
  88.  * above as 1 and then #includes this file.  The following directives make
  89.  * sure that the other macros are set to the correct defaults.
  90.  * ------------------------------------------------------------------------*/
  91.  
  92. #ifndef MACHDEP_GOFER
  93. #define MACHDEP_GOFER   0
  94. #endif
  95. #ifndef MACHDEP_GOFC
  96. #define MACHDEP_GOFC    0
  97. #endif
  98. #ifndef MACHDEP_RUNTIME
  99. #define MACHDEP_RUNTIME 0
  100. #endif
  101.  
  102. /* --------------------------------------------------------------------------
  103.  * Find information about a file:
  104.  * ------------------------------------------------------------------------*/
  105.  
  106. #if (MACHDEP_GOFER | MACHDEP_GOFC)
  107. #if RISCOS
  108. typedef struct { unsigned hi, lo; } Time;
  109. #define timeChanged(now,thn)    (now.hi!=thn.hi || now.lo!=thn.lo)
  110. #define timeSet(var,tm)        var.hi = tm.hi; var.lo = tm.lo
  111. #else
  112. typedef time_t Time;
  113. #define timeChanged(now,thn)    (now!=thn)
  114. #define timeSet(var,tm)        var = tm
  115. #endif
  116.  
  117. static Void local getFileInfo    Args((String, Time *, Long *));
  118.  
  119. static Void local getFileInfo(s,tm,sz)    /* find time stamp and size of file*/
  120. String s;
  121. Time   *tm;
  122. Long   *sz; {
  123. #if RISCOS                /* get file info for RISCOS -- JBS */
  124.     os_regset r;            /* RISCOS PRM p.850 and p.837       */
  125.     r.r[0] = 17;            /* Read catalogue, no path       */
  126.     r.r[1] = (int)s;
  127.     os_swi(OS_File, &r);
  128.     if(r.r[0] == 1 && (r.r[2] & 0xFFF00000) == 0xFFF00000) {
  129.     tm->hi = r.r[2] & 0xFF;        /* Load address (high byte)       */
  130.     tm->lo = r.r[3];        /* Execution address (low 4 bytes) */
  131.     }
  132.     else                /* Not found, or not time-stamped  */
  133.     tm->hi = tm->lo = 0;
  134.     *sz = (Long)(r.r[0] == 1 ? r.r[4] : 0);
  135. #else                    /* normally just use stat()       */
  136.     static struct stat scbuf;
  137.     stat(s,&scbuf);
  138.     *tm = scbuf.st_mtime;
  139.     *sz = (Long)(scbuf.st_size);
  140. #endif
  141. }
  142. #endif
  143.  
  144. #if RISCOS                /* RISCOS needs access()       */
  145. int access(char *s, int dummy) {    /* Give 1 iff cannot access file s */
  146.     os_regset r;            /* RISCOS PRM p.850    -- JBS       */
  147.     assert(dummy == 0);
  148.     r.r[0] = 17; /* Read catalogue, no path */
  149.     r.r[1] = (int)s;
  150.     os_swi(OS_File, &r);
  151.     return r.r[0] != 1;
  152. }
  153. #endif
  154.  
  155. /* --------------------------------------------------------------------------
  156.  * stat and chdir for MPW:
  157.  * ------------------------------------------------------------------------*/
  158.  
  159. #if MPW
  160.  
  161. #include <Values.h>
  162. #include <Types.h>          /*  Basic type definitions         */
  163. #include <Files.h>
  164. #if !THINKC
  165. #include <Strings.h>
  166. #endif
  167.  
  168. stat(file,sb)
  169. char *file;
  170. struct stat *sb;
  171. {
  172.   FileParam finfo;
  173.   short volnum;
  174.   
  175.   GetVol(NULL,&volnum);
  176.  
  177.   finfo.ioCompletion = NULL;
  178. #if THINKC
  179.   finfo.ioNamePtr = (StringPtr) c2pstr(file);
  180. #else
  181.   finfo.ioNamePtr = c2pstr(file);
  182. #endif
  183.   finfo.ioVRefNum = volnum;
  184.   finfo.ioFVersNum = 0;
  185.   finfo.ioFDirIndex = 0;
  186.   
  187.   PBGetFInfo((ParmBlkPtr)&finfo,FALSE);
  188.   
  189.   /* Use getfinfo to return the modification time for "file" */
  190.   sb->st_mtime = finfo.ioFlMdDat;
  191.   sb->st_size = finfo.ioFlLgLen;
  192.  
  193.  /* Now restore the string! */
  194.  p2cstr(file);
  195. }
  196.  
  197.  
  198. chdir(s)
  199. char *s;
  200. {
  201.   WDPBRec pb;
  202.   pb.ioCompletion = NULL;
  203.   c2pstr(s);
  204.   pb.ioNamePtr=(StringPtr)s;
  205.   pb.ioVRefNum = 0;
  206.   pb.ioWDDirID = 0;
  207.   PBHSetVol(&pb,FALSE);
  208.   p2cstr(s);
  209.  
  210.   /* Check whether the directory exists */
  211.   if(pb.ioResult == noErr)
  212.     {
  213. #if MAC
  214.       /* If so, get the volume reference and directory ID and save it */
  215.       PBHGetVol(&pb,FALSE);
  216.       savedir(pb.ioVRefNum,pb.ioWDDirID,FALSE);
  217. #endif
  218.       return(0);
  219.     }
  220.   else
  221.     return(1);
  222. }
  223. #endif
  224.  
  225.  
  226. /* --------------------------------------------------------------------------
  227.  * Get time/date stamp for inclusion in compiled files:
  228.  * ------------------------------------------------------------------------*/
  229.  
  230. #if MACHDEP_GOFC
  231. #include <time.h>
  232. String timeString() {            /* return time&date string       */
  233.     time_t clock;            /* must end with '\n' character       */
  234.     time(&clock);
  235.     return(ctime(&clock));
  236. }
  237. #endif
  238.  
  239. /* --------------------------------------------------------------------------
  240.  * Garbage collection notification:
  241.  * ------------------------------------------------------------------------*/
  242.  
  243. #if  (MACHDEP_GOFER |